package com.ly.mpayment.rest.up;

import com.ly.mpayment.core.util.Config;
import com.ly.mpayment.core.util.CookieRedis;
import com.ly.mpayment.core.util.DateUtils;
import com.ly.mpayment.persist.entity.*;
import com.ly.mpayment.persist.service.debitlog.IDebitLogService;
import com.ly.mpayment.persist.service.downorderlog.IDownOrderLogService;
import com.ly.mpayment.persist.service.downorderrefund.IDownOrderRefundService;
import com.ly.mpayment.persist.service.downrechargeflow.IDownRechargeFlowService;
import com.ly.mpayment.persist.service.downshopinfo.IDownShopInfoService;
import com.ly.mpayment.persist.service.matchingstrategy.IMatchingStrategyService;
import com.ly.mpayment.persist.service.uporder.IUporderService;
import com.ly.mpayment.persist.service.uporderlog.IUpOrderLogService;
import com.ly.mpayment.persist.service.uporderrefund.IUpOrderRefundService;
import com.ly.mpayment.persist.service.upshopinfo.IUpShopInfoService;
import com.ly.mpayment.persist.service.upshoppro.IUpShopProService;
import com.ly.mpayment.rest.recharge.OrderProcessing;
import com.ly.mpayment.rest.recharge.OrderThread;
import com.ly.mpayment.rest.recharge.RechargeRest;
import com.ly.mpayment.rest.up.anchang.AnChangRest;
import com.ly.mpayment.rest.up.chenhan.ChenHanRest;
import com.ly.mpayment.rest.up.chinaunicom.ChinaUnicomRest;
import com.ly.mpayment.rest.up.dongye.DongYeRest;
import com.ly.mpayment.rest.up.fanxin.FanXinRest;
import com.ly.mpayment.rest.up.feizhidu.FeiZhiDuRest;
import com.ly.mpayment.rest.up.fengniu.FengNiuRest;
import com.ly.mpayment.rest.up.fulu.FuLuRest;
import com.ly.mpayment.rest.up.guangmu.GuangMuRest;
import com.ly.mpayment.rest.up.guochuang.GuoChuangRest;
import com.ly.mpayment.rest.up.hebao.HeBaoRest;
import com.ly.mpayment.rest.up.honglu.HongLuRest;
import com.ly.mpayment.rest.up.hongshi.HongShiRest;
import com.ly.mpayment.rest.up.huarongxunfang.HuaRongRest;
import com.ly.mpayment.rest.up.huisutong.HuiSuTongRest;
import com.ly.mpayment.rest.up.hunanjb.HuNanJob;
import com.ly.mpayment.rest.up.jiamiduo.JiaMiDuoRest;
import com.ly.mpayment.rest.up.jiangren.JiangRenRest;
import com.ly.mpayment.rest.up.jiuya.JiuYaRest;
import com.ly.mpayment.rest.up.juesheng.JueShengRest;
import com.ly.mpayment.rest.up.longzhang.LongZhangRest;
import com.ly.mpayment.rest.up.maiyuan.MaiYuanRest;
import com.ly.mpayment.rest.up.maiyuan2.MaiYuan2Rest;
import com.ly.mpayment.rest.up.maiyuanhf.MaiYuanhfRest;
import com.ly.mpayment.rest.up.masike.MaSiKeRest;
import com.ly.mpayment.rest.up.meijia.MeiJiaRest;
import com.ly.mpayment.rest.up.napi.NaPiRest;
import com.ly.mpayment.rest.up.qgliantong.QuanGuoLtRest;
import com.ly.mpayment.rest.up.qingchi.QingChiRest;
import com.ly.mpayment.rest.up.qinghaiyd.QingHaiYd;
import com.ly.mpayment.rest.up.renxingkeji.RenXingRest;
import com.ly.mpayment.rest.up.sanchongmao.SanChongMaoRest;
import com.ly.mpayment.rest.up.shuoruan.ShouRuanRest;
import com.ly.mpayment.rest.up.shuwang.ShuWangRest;
import com.ly.mpayment.rest.up.suhu.SuHuRest;
import com.ly.mpayment.rest.up.tianzhong.TianZhongRest;
import com.ly.mpayment.rest.up.wanlifanghe.WanLiFangHeRest;
import com.ly.mpayment.rest.up.wswpay.WswpayRest;
import com.ly.mpayment.rest.up.xinjin.XinJinRest;
import com.ly.mpayment.rest.up.xuanjie.XuanJieRest;
import com.ly.mpayment.rest.up.yezhikeji.YezhikejiRest;
import com.ly.mpayment.rest.up.yiche.YiTongDaRest;
import com.ly.mpayment.rest.up.yingyou.YingYouRest;
import com.ly.mpayment.rest.up.yishuo.YiShuoRest;
import com.ly.mpayment.rest.up.yixinyou.YiXinYouRest;
import com.ly.mpayment.rest.up.youxinya.YouXinYaRest;
import com.ly.mpayment.rest.up.yujing.YuJingRest;
import com.ly.mpayment.rest.up.yunchuang.YunChuangRest;
import com.ly.mpayment.rest.up.yunshan.YunShanRest;
import com.ly.mpayment.rest.up.zhaoguo.ZhaoGuoRest;
import com.ly.mpayment.rest.up.zhengbang.ZhengBangRest;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class OrderHandler {

    Logger logger = Logger.getLogger(OrderHandler.class);

    @Autowired
    IDownShopInfoService shopService;

    @Autowired
    IUporderService orderService;

    @Autowired
    IDownOrderLogService logDownService;

    @Autowired
    IUpOrderLogService logUpService;

    @Autowired
    IDownRechargeFlowService downRechargeFlowService;

    @Autowired
    IDownOrderRefundService fundService;

    @Autowired
    IUpOrderRefundService refundSerevice;

    @Autowired
    IDebitLogService logService;

    @Autowired
    IUpShopInfoService upShopService;

    @Autowired
    IUporderService upOrderService;

    @Autowired
    ThreadPoolTaskExecutor taskExecutor;

    @Autowired
    private OrderProcessing orderProcessing;

    @Autowired
    private IUpShopProService upShopProService;

    @Autowired
    OrderThread orderThread;

    @Autowired
    IMatchingStrategyService matchStrategyService;

    @Autowired
    private NaPiRest naPiRest;

    public void orderHanlderSuccess(UpOrder order, String msg) {
        try{
            order = upOrderService.findByCallId(order.getUporderuuid());
            if (order != null &&  (order.getStatus() == Config.status[0] || order.getStatus() == Config.status[10]
                    || order.getStatus() == Config.status[11])) {
                try{
                    upOrderService.addOrderMsg(order, msg == null ? "" : msg.toString());
                }catch (Exception e){
                    e.printStackTrace();
                    upOrderService.addOrderMsg(order, msg == null ? "" : msg.toString());
                }
                DownRechargeFlow flow = order.getDownRechargeFlow();
                flow = upOrderService.updateOrderBalance(order, flow, null);
                orderProcessing.sendResultDownShop(flow,true);
            }
        }catch (Exception e){
            e.printStackTrace();
            logger.info("添加成功异常:"+order.getUpphonenum()+"error:"+e.getMessage());
            if(order != null){
                order.setRemark(msg);
                RechargeRest.successUpOrder.add(order);
                logger.info("添加成功的订单到队列:"+order.getUpphonenum());
            }
        }
    }


    /**
     * 订单失败 检查是否包含重复提交策略
     * @param order
     * @param errorMsg
     */
    public void orderHanlderFailt(UpOrder order, String errorMsg) {
        logger.info("orderHanlderFailt:"+order.getUpphonenum());
        final UpShopInfo upShopInfo = upShopService.findByUserId(order.getUserOrder().getUseruuid());
        if(upShopInfo == null){
            logger.info("渠道用户不存在:"+order.getUpphonenum());
            return ;
        }
        //考虑人工失败的订单不能转人工 直接失败
        //如果开启提交次数。则次数满足后在转人工
        //orderHandler.orderHanlderRepeat(order,upShopInfo,"","msg",Config.status[2]);
        if(order != null && order.getRepeatNum() >= upShopInfo.getRepeatNum() && (upShopInfo.getArtificial() || order.getUpShopPro().getArtificial()) && !Config.orderStatus[2].equals(order.getStatusremark())){
            logger.info("转人工:"+order.getUpphonenum());
            order.setStatus(Config.status[11]);
            this.orderService.updateOrder(order);
        }else if(order.getStatusremark().equals(Config.orderStatus[2])){
            //直接失败
            orderFailt(order,"人工失败");
        }else{
            //不转人工则检查是否进行重复提交
            orderHanlderRepeat(order,upShopInfo,errorMsg,Config.status[2]);
        }
    }

    /**
     * 直接失败订单
     * @param order
     * @param errorMsg
     */
    public void orderFailt(UpOrder order, String errorMsg){
//        taskExecutor.execute(new Runnable() {
//            @Override
//            public void run() {
//
//            }
//        });
        try {
            //直接失败
            downRechargeFlowService.updateOrderFailt(order,errorMsg != null && errorMsg.length() > 100 ? errorMsg.substring(0,100) : errorMsg);
        }catch (Exception e){
            e.printStackTrace();
            if(order != null){
                logger.info("添加失败的订单到队列:"+order.getUpphonenum()+","+e.getMessage());
                order.setRemark(errorMsg != null && errorMsg.length() > 100 ? errorMsg.substring(0,100) : errorMsg);
                RechargeRest.failtUpOrder.add(order);
            }
        }
    }



    /**
     * 订单重复提交
     * @param orderUp
     */
    public void orderHanlderRepeat(final UpOrder orderUp,final UpShopInfo upShopInfo,String msg,Integer status) {
        taskExecutor.execute(new Runnable() {
            @Override
            public void run() {
                if(orderUp == null || upShopInfo == null){
                    logger.info("数据异常..........:"+msg+":"+orderUp.getUpphonenum());
                    return;
                }
                UpOrder order = upOrderService.findByCallId(orderUp.getUporderuuid());
                if(order == null){
                    logger.info("订单异常:"+msg+":"+orderUp.getUpphonenum());
                    return;
                }

                //订单失败则进入重复循环
                if(status == Config.status[2]){
                    //order.getRepeatNum() >= order.getUpShopPro().getRepeatNum() || 产品次数先不做
                    logger.info("订单失败,重试:"+order.getUpphonenum()+":"+order.getUporderuuid());
                    DownRechargeFlow flow = downRechargeFlowService.findById(order.getDownRechargeFlow().getDownorderuuid());
                    //重复提交 检查订单匹配类型
                    //自动手动 0 自动 1手动
                    try{
                        switch (flow.getDownShopProduct().getAuto()){
                            case 0:
                                repeatUporder(order,upShopInfo,status,msg,flow);
                                break;
                            case 1:
                                //手动查询 上游产品设置的提交次数。同一个供货商 或产品 提交次数 那个先到 使用那个
                                //达到次数后切换下一个供货商。都使用完后失败回去。
                                logger.info("manualUporder:"+order.getUpphonenum()+","+orderUp.getRemark()+","+msg);
                                manualUporder(order,upShopInfo,status,msg,flow);
                                break;
                        }
                    }catch (Exception e){
                        e.printStackTrace();
                        logger.info(e.getMessage()+":flow+"+flow.getDowonphonenum()+":flow"+flow.getDownorderuuid());
                    }
                } else if(status == Config.status[1]){
                    logger.info("成功订单:"+order.getUpphonenum());
                    order.setRemark(msg == null ? "成功" : msg);
                    RechargeRest.successUpOrder.add(order);
                } else {
                    logger.info("未知状态人工:"+order.getUpphonenum());
                    upOrderService.addOrderMsg(order,"未知状态:"+status);
                }
            }
        });
    }

    /**
     * 手动提交 按手动匹配 供应商顺序提交
     * @param order
     * @param upShopInfo
     * @param status
     * @param msg
     * @param flow
     */
    public void manualUporder(UpOrder order,UpShopInfo upShopInfo,Integer status,String msg,DownRechargeFlow flow){
        //todo 增加订单次数检查 和最后一次上游渠道用户检查
        if(order.getRepeatNum() >= upShopInfo.getRepeatNum()){
            if(checkNumDown(flow,"") == 1){
                logger.info("手动匹配错误,重复提交超过次数:"+order.getUpphonenum()+","+order.getRepeatNum());
                //order.setRemark(msg == null ? "手动重试未找到产品,失败" : msg);
                //RechargeRest.failtUpOrder.add(order);
                orderFailt(order,msg == null ? "手动重试未找到产品,失败" : msg);
                return;
            }
        }

        //订单的执行次数超过配置则失败
        if(checkNum(flow,"") ) {
            orderFailt(order,"重试次数达到上限,订单失败,"+msg);
            return;
        }


        //失败上一次订单，重新创建上游订单
        order.setStatus(Config.status[2]);
        order.setRemark(order.getRemark()+",匹配失败重提,当前订单失败");
        order.setUpendtime(DateUtils.getNowDate());
        order.setCallBack(Config.callStatus[1]);
        this.upOrderService.updateOrder(order);
        //第n+1次手动提交
        orderThread.manualMatchOrder(flow,order.getRepeatNum()+1,order);
    }


    public int checkNumDown(DownRechargeFlow flow,String upuseruuid){
        //如果产品匹配次数和订单提交次数相等 则失败
        int downNum = this.matchStrategyService.downCount(flow.getDownShopProduct().getDownprouuid());
        //int upNum = this.upOrderService.upCount(flow.getDownorderuuid());
        return downNum;
    }
    /**
     * 检查次数 订单次数大于匹配次数
     * 订单匹配次数大于1的表示不走重复提交 走手动匹配指定渠道提交
     * @param flow
     * @return
     */
    public boolean checkNum(DownRechargeFlow flow,String upuseruuid){
        //如果产品匹配次数和订单提交次数相等 则失败
        int downNum = this.matchStrategyService.upSumUpUser(flow.getDownShopProduct().getDownprouuid());
        int upNum = this.upOrderService.upCount(flow.getDownorderuuid());
        return upNum >= downNum;
    }

    /**
     * 自动提交
     * @param order
     * @param status
     * @param msg
     * @param flow
     */
    public void repeatUporder(UpOrder order,UpShopInfo upShopInfo,Integer status,String msg,DownRechargeFlow flow){
        //自动匹配如果提交次数没有小于设定的提交次数则继续上一个渠道产品提交
        if(order.getRepeatNum() >= upShopInfo.getRepeatNum() ){
            //查询所有已经匹配过的上游产品id数组
            //自动每次带入上一次的产品id查询。 不包含的产品id进行充值 ，直到自动产品返回为0 ，则失败订单
            //查询订单可重复匹配的产品
            List<UpOrder> upShopProducts = upOrderService.findByDownOrderId(order.getDownRechargeFlow().getDownorderuuid());
            if(upShopProducts == null || upShopProducts.isEmpty()){
                logger.info("上次匹配产品错误,订单异常:"+order.getUpphonenum());
                this.upOrderService.addOrderMsg(order,"产品错误,订单异常:"+status);
                return;
            }

            final List<String> lastUp = new ArrayList<>();
            final Integer size = upShopProducts.size();
            for (int i = 0 ; i < size ; i++){
                if(!lastUp.contains(upShopProducts.get(i).getUpShopPro().getUpprouuid())){
                    lastUp.add(upShopProducts.get(i).getUpShopPro().getUpprouuid());
                }
            }

            //同一个产品的最大重试次数
            if(lastUp != null && lastUp.size() >= Integer.parseInt(CookieRedis.get("repeatNum") == null ? "10" : CookieRedis.get("repeatNum"))){
                logger.info("超过提交重复次数,失败订单10:"+order.getUpphonenum());
                orderFailt(order,msg == null ? "最大重试次数不能超过10次" : msg);
                return;
            }
            List<UpShopProduct> ups = upShopProService.findOrderMatchRepeat(flow.getOperators(), flow.getProvince(),
                    flow.getBusCode(), flow.getDiscountAmount(),
                    flow.getDownShopProduct().getDownfacevalue(),flow.getDownShopProduct().getCityName(),lastUp);

            if(ups == null || ups.isEmpty()){
                logger.info("重试未找到产品失败1:"+order.getUpphonenum());
                //order.setRemark(msg == null ? "重试未找到产品失败" : msg);
                //RechargeRest.failtUpOrder.add(order);
                orderFailt(order,msg == null ? "重试未找到产品失败" : msg);
                return;
            }
            orderExecute(ups,order,flow);
        }else{
            final List<String> lastUp = new ArrayList<>();
            lastUp.add(order.getUpShopPro().getUpprouuid());
            List<UpShopProduct> ups = upShopProService.findOrderMatchIn(flow.getOperators(), flow.getProvince(),
                    flow.getBusCode(), flow.getDiscountAmount(),
                    flow.getDownShopProduct().getDownfacevalue(),flow.getDownShopProduct().getCityName(),lastUp);
            if(ups == null || ups.isEmpty()){
                logger.info("重试未找到产品失败2:"+order.getUpphonenum());
//                /order.setRemark(msg == null ? "重试未找到产品失败" : msg);
                //RechargeRest.failtUpOrder.add(order);
                orderFailt(order,msg == null ? "重试未找到产品失败" : msg);
                return;
            }
            orderExecute(ups,order,flow);
        }

    }

    private void orderExecute(List<UpShopProduct> ups,UpOrder order,DownRechargeFlow flow){
        if(ups != null){
            //失败上一次订单，重新创建上游订单
            order.setStatus(Config.status[2]);
            order.setRemark("失败重提,当前订单失败");
            order.setUpendtime(DateUtils.getNowDate());
            order.setCallBack(Config.callStatus[1]);
            this.upOrderService.updateOrder(order);
            logger.info("重提订单:"+order.getUpphonenum());
            //如果产品id不等，则切换提交次数 从0开始
            if(!ups.get(0).getUser().getUseruuid().equals(order.getUserOrder().getUseruuid())){
                //重提订单 第 n+1次提交
                orderThread.orderExecute(flow,ups.get(0),1);
            }else{
                //重提订单 第 n+1次提交
                orderThread.orderExecute(flow,ups.get(0),order.getRepeatNum()+1);
            }
        }else{
            logger.info("重提订单获取产品失败:"+order.getUpphonenum());
        }
    }

    @Autowired
    private FanXinRest fanXinRest;

    @Autowired
    private ChinaUnicomRest chinaUnicomRest;

    @Autowired
    private ChenHanRest chenHanRest;

    @Autowired
    private ShuWangRest shuWangRest;

    @Autowired
    private GuangMuRest guangMuRest;

    @Autowired
    private QingChiRest qingChiRest;

    @Autowired
    private LongZhangRest longZhangRest;

    @Autowired
    private YuJingRest yuJingRest;

    @Autowired
    private YiTongDaRest yiTongDaRest;

    @Autowired
    private YezhikejiRest yezhikejiRest;

    @Autowired
    private ZhengBangRest zhengBangRest;

    @Autowired
    private MaiYuanRest maiYuanRest;

    @Autowired
    private YouXinYaRest youXinYaRest;

    @Autowired
    private FeiZhiDuRest feiZhiDuRest;

    @Autowired
    private XuanJieRest xuanJieRest;

    @Autowired
    private HongLuRest hongLuRest;

    @Autowired
    private YunChuangRest yunChuangRest;

    @Autowired
    private JiuYaRest jiuYaRest;

    @Autowired
    private WanLiFangHeRest wanLiFangHeRest;

    @Autowired
    private JiaMiDuoRest jiaMiDuoRest;

    @Autowired
    private DongYeRest dongYeRest;

    @Autowired
    private SuHuRest suHuRest;

    @Autowired
    private HuaRongRest huaRongRest;

    @Autowired
    private MeiJiaRest meiJiaRest;

    @Autowired
    private ShouRuanRest shouRuanRest;

    @Autowired
    private MaiYuanhfRest maiYuanhfRest;

    @Autowired
    private FuLuRest fuLuRest;

    @Autowired
    private QingHaiYd qingHaiYd;

    @Autowired
    private JiangRenRest jiangRenRest;

    @Autowired
    private YiShuoRest yiShuoRest;

    @Autowired
    private YunShanRest yunShanRest;

    @Autowired
    private GuoChuangRest guoChuangRest;

    @Autowired
    private MaiYuan2Rest maiYuan2Rest;

    @Autowired
    private YiXinYouRest yiXinYouRest;

    @Autowired
    private HeBaoRest heBaoRest;

    @Autowired
    private JueShengRest jueShengRest;

    @Autowired
    private HuiSuTongRest huiSuTongRest;

    @Autowired
    private SanChongMaoRest sanChongMaoRest;

    @Autowired
    FengNiuRest fengNiuRest;

    @Autowired
    YingYouRest yingYouRest;

    @Autowired
    MaSiKeRest maSiKeRest;

    @Autowired
    HongShiRest hongShiRest;

    @Autowired
    TianZhongRest tianZhongRest;

    @Autowired
    WswpayRest wswpayRest;

    @Autowired
    RenXingRest renXingRest;

    @Autowired
    AnChangRest anChangRest;

    @Autowired
    HuNanJob huNanJob;

    @Autowired
    private XinJinRest xinJinRest;

    @Autowired
    private QuanGuoLtRest quanGuoLtRest;

    @Autowired
    private ZhaoGuoRest zhaoGuoRest;

    /**
     * 提交订单
     * @param order
     * @param shop
     */
    public void commitOrder(UpOrder order, UpShopInfo shop) {
        //检查上游渠道状态是否正常
        if(order.getUserOrder().getUserstatus() == Config.userStatus ){
            switch (shop.getShopnum()) {
//                case Config.fanxin:
//                    fanXinRest.commitOrder(order,shop);
//                    break;
//                case Config.chinaunicom:
//                    chinaUnicomRest.commitOrder(order,shop);
//                    break;
//                case Config.chenhan:
//                    chenHanRest.commitOrder(order,shop);
//                    break;
//                case Config.shuwang:
//                    shuWangRest.commitOrder(order,shop);
//                    break;
                    case Config.guangmu:
                        guangMuRest.commitOrder(order,shop);
                        break;
                    case Config.qingchi:
                        qingChiRest.commitOrder(order,shop);
                        break;
//                case Config.longzhang:
//                    longZhangRest.commitOrder(order,shop);
//                    break;
//                case Config.yujing:
//                    yuJingRest.commitOrder(order,shop);
//                    break;
//                case Config.yiche:
//                    yiTongDaRest.commitOrder(order,shop);
//                    break;
//                case Config.zhengbang:
//                    zhengBangRest.commitOrder(order,shop);
//                    break;
//                case Config.youxinya:
//                    youXinYaRest.commitOrder(order,shop);
//                    break;
//                case Config.feizhidu:
//                    feiZhiDuRest.commitOrder(order,shop);
//                    break;
//                case Config.yuanmai:
//                    maiYuanRest.commitOrder(order,shop);
//                    break;
//                case Config.yezhikeji:
//                    yezhikejiRest.commitOrder(order,shop);
//                    break;
//                case Config.xuanjie:
//                    xuanJieRest.commitOrder(order,shop);
//                    break;
//                case Config.honglu:
//                    hongLuRest.commitOrder(order,shop);
//                    break;
//                case Config.yunchuang:
//                    yunChuangRest.commitOrder(order,shop);
//                    break;
//                case Config.jiuya:
//                    jiuYaRest.commitOrder(order,shop);
//                    break;
//                case Config.wanlifanghe:
//                    wanLiFangHeRest.commitOrder(order,shop);
//                    break;
//                case Config.jiamiduo:
//                    jiaMiDuoRest.commitOrder(order,shop);
//                    break;
//                case Config.dongye:
//                    dongYeRest.commitOrder(order,shop);
//                    break;
                  case Config.suhukeji:
                      suHuRest.commitOrder(order,shop);
                      break;
//                case Config.huarongxunfang:
//                    huaRongRest.commitOrder(order,shop);
//                    break;
//                case Config.meijia:
//                    meiJiaRest.commitOrder(order,shop);
//                    break;
//                case Config.shuoruan:
//                    shouRuanRest.commitOrder(order,shop);
//                    break;
//                case Config.maiyuanhf:
//                    maiYuanhfRest.commitOrder(order,shop);
//                    break;
//                case Config.qinghaijb:
//                    order.setRemark("等待处理");
//                    upOrderService.updateOrder(order);
//                    break;
//                case Config.fulu:
//                    fuLuRest.commitOrder(order,shop);
//                    break;
//                case Config.qinghaiyd:
//                    qingHaiYd.commitOrder(order,shop);
//                    break;
//                case Config.jiangren:
//                    jiangRenRest.commitOrder(order,shop);
//                    break;
//                case Config.yishuo:
//                    yiShuoRest.commitOrder(order,shop);
//                    break;
//                case Config.yunshan:
//                    yunShanRest.commitOrder(order,shop);
//                    break;
//                case Config.guochuang:
//                    guoChuangRest.commitOrder(order,shop);
//                    break;
//                case Config.napikeji:
//                    naPiRest.commitOrder(order,shop);
//                    break;
//                case Config.maiyuan2:
//                    maiYuan2Rest.commitOrder(order,shop);
//                    break;
//                case Config.yixinyou:
//                    yiXinYouRest.commitOrder(order,shop);
//                    break;
//                case Config.hebao:
//                    heBaoRest.commitOrder(order,shop);
//                    break;
//                case Config.juesheng:
//                    jueShengRest.commitOrder(order,shop);
//                    break;
//                case Config.huisutong:
//                    huiSuTongRest.commitOrder(order,shop);
//                    break;
//                case Config.sanchongmao:
//                    sanChongMaoRest.commitOrder(order,shop);
//                    break;
//                case Config.fengniu:
//                    fengNiuRest.commitOrder(order,shop);
//                    break;
//                case Config.yingyou:
//                    yingYouRest.commitOrder(order,shop);
//                    break;
//                case Config.masike:
//                    maSiKeRest.commitOrder(order,shop);
//                    break;
//                case Config.hongshi:
//                    hongShiRest.commitOrder(order,shop);
//                    break;
//                case Config.tianzhong:
//                    tianZhongRest.commitOrder(order,shop);
//                    break;
//                case Config.wswpay:
//                    wswpayRest.commitOrder(order,shop);
//                    break;
//                case Config.renxingkeji:
//                    renXingRest.commitOrder(order,shop);
//                    break;
//                case Config.anchang:
//                    anChangRest.commitOrder(order,shop);
//                    break;
//                case Config.hunanjob:
//                    order.setRemark("等待处理");
//                    upOrderService.updateOrder(order);
////                    OrderProcessing.hunanjobOrder.add(order);
//                    break;
//                case Config.xinjin:
//                    xinJinRest.commitOrder(order,shop);
//                    break;
//                case Config.qgliantong:
//                    quanGuoLtRest.commitOrder(order,shop);
//                    break;
//                case Config.zhaoguo:
//                    zhaoGuoRest.commitOrder(order,shop);
//                    break;
//                case Config.renxingkeji:
//                    Integer i = (int)(Math.random()*100);
//                    if(i % 2 == 0){
//                        orderHanlderRepeat(order,shop,"成功",2);
//                    }else{
//                        orderHanlderRepeat(order,shop,"失败",3);
//                    }
//                    break;
                default:
                    order.setRemark("等待处理");
                    upOrderService.updateOrder(order);
//                    logger.info("渠道编号不正确:" + shop.getShopnum());
//                    order.setStatus(Config.status[11]);
//                    order.setRemark("渠道编号不正确或配置错误，订单未提交");
//                    upOrderService.updateOrder(order);
//                    Integer i = (int)(Math.random()*100);
//                    if(i % 3 == 0){
//                        orderHanlderRepeat(order,shop,"成功",2);
//                    }else{
                        //orderHanlderRepeat(order,shop,"失败",3);
//                    }
                    break;
            }
        }else{
            order.setStatus(Config.status[11]);
            order.setRemark("订单未提交,渠道状态关闭");
            upOrderService.updateOrder(order);
        }
    }

}
